<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .login-box1{
            width:500px;
            height: 800px;
            background-color: #ecefff;  
            margin: 100px auto;    
        }
        .al{
           text-align: center;
           line-height: 200px;
           font-size: 50px;
        }
        .login-box{
            width: 400px;
            height: 400px;
            margin: 10px auto;
            background-color: white;
            border-radius: 20px;
        }
        .login-box .title{
            font-weight: bold;
            line-height: 80px;
            text-align: center;
        }
        .login-box .block{
            margin: 30px 0;
        }
        .login-box .block input{
            height: 40px;
            padding-left: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: 100%;
            outline: none;
            box-sizing: border-box;
        }
        .login-box .blocka input{
            height: 40px;
            padding-left: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: 100%;
            outline: none;
            box-sizing: border-box;
            background-color: rgb(86,121,254);
            border-radius: 10px;
        }
    </style>
</head>
<body>
    <div class="login-box1">
        <div class="al">阿里云盘</div>
        <div class="login-box">
            <div class="title">注册新账号</div>
            <div class="block">
                <input type="text" placeholder="请输入账号">
            </div>
            <div class="block">
                <input type="password" placeholder="请输入密码">
            </div>
            <div class="block">
                <input type="text" placeholder="确认密码">
            </div>
            <div class="blocka">
                <input type="button" value="注册">
            </div>
        </div>
    </div>
</body>
</html>
<script src="./Promise.js"></script>
<script>
     //获取3个input输入框
    var inputs = document.querySelectorAll('.login-box .block input');
    //给注册按钮添加点击事件
    inputs[3].onclick = function(){
        //对表单进行校验（为空校验，格式校验）
        if( inputs[0].value && inputs[1].value && inputs[2].value ){
            //判断密码为任意的四个数字
            if( /^\d{4}$/.test(inputs[1].value) && inputs[1].value == inputs[2].value ){
                ajax( 'get' , 'https://yantianfeng.com/api/register' , { username:inputs[0].value , password:inputs[1].value  } , function(user){
                    console.log(user);
                })
            }else{
                alert('请输入正确的手机号/密码/两次输入的密码不一致！')
            }
        }else{
            alert('用户名/密码不能为空')
        }
    }
</script>